package com.lingnan.excel;

import com.alibaba.excel.EasyExcel;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

public class ExcelTestDemo {
    /**
     * easyexcel写操作
     */
    @Test
    public void testWriter(){

        // 创建生成文件路径
        String fileName = "C:\\Users\\wweca\\Desktop\\学生信息.xlsx";

        // 创建生成文件内容
        Student student = null;
        List<Student> studentList = new ArrayList<>();
        for (int i = 1; i <= 10; i++) {
            student = new Student();
            student.setStudentId(i);
            student.setStudentName("学生名称:"+i);
            studentList.add(student);
        }

        // 执行写操作
        EasyExcel.write(fileName,Student.class).sheet("学生栏目信息").doWrite(studentList);
    }

    /**
     * easyexcel读操作
     */
    @Test
    public void testRead(){
        // 读取文件路径
        String fileName = "C:\\Users\\wweca\\Desktop\\学生信息.xlsx";
        EasyExcel.read(fileName,Student.class,new ExcelListener()).sheet().doRead();
    }
}
